package keeto.com.vn.bms.ui.adapter;

import java.util.List;

import keeto.com.vn.bms.ui.activity.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class WeekAdapter extends BaseAdapter {

	private Context mContext;
	private int selectedDay;
	private List<String> daysOfWeek;
	private LayoutInflater mInflater;
	private View previousView;
	

	public WeekAdapter(Context context, int selectedDay, List<String> daysOfWeek) {
		super();

		this.mContext = context;
		this.selectedDay = selectedDay;
		this.daysOfWeek = daysOfWeek;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return daysOfWeek.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return daysOfWeek.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		final TextView tvday;
		if (convertView == null) {
			v = mInflater.inflate(R.layout.item_calendar, parent, false);
			LayoutParams layoutParams = v.getLayoutParams();
			final float scale = mContext.getResources()
					.getDisplayMetrics().density;
			int pixels = (int) (40 * scale + 0.5f);
			layoutParams.height = pixels;
			v.setLayoutParams(layoutParams);
		}
		tvday = (TextView) v.findViewById(R.id.tv_date_cal);
		// for (int i = 0; i < daysOfWeek.size(); i++) {
		tvday.setText(daysOfWeek.get(position));
		String selected=selectedDay+"";
		if(selected.length()==1){
			selected="0"+selectedDay;
		}


		if (daysOfWeek.get(position).equals(selected)) {
			setSelected(v);
			previousView=v;
		} else {
			v.setBackgroundResource(R.color.white);
		}

		return v;
	}
	public View setSelected(View view) {
		if (previousView != null) {
			previousView.setBackgroundResource(R.color.white);
		}
		previousView = view;
		view.setBackgroundResource(R.drawable.selected_day);
		return view;
	}

}
